package com.mikufufu.blog.controller.admin;

import com.mikufufu.blog.common.annotation.OperationLog;
import com.mikufufu.blog.common.entity.AjaxResult;
import com.mikufufu.blog.common.enums.ModuleType;
import com.mikufufu.blog.common.enums.OperationType;
import com.mikufufu.blog.service.EmailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Email;

@Api(tags = "邮件管理")
@Validated
@RestController
@RequestMapping("/admin/email")
public class EmailController {

    @Autowired
    private EmailService emailService;

    @GetMapping("/sendTestEmail")
    @ApiOperation(value = "发送测试邮件")
    @OperationLog(module = ModuleType.SYSTEM,type = OperationType.SEND_EMAIL, description = "发送邮件")
    @ApiImplicitParam(name = "to", value = "收件人邮箱", required = true, dataType = "String", paramType = "query")
    public AjaxResult<Void> sendTestEmail(@Email(message = "请输入正确的邮箱地址") String to) {
        emailService.sendHtmlEmail("小缡", to, "测试邮件", "<h1 style=\"color: red;\">测试邮件</h1>");
        return AjaxResult.success();
    }
}
